home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1997-12-19 | 10.2 KB | 300 lines | [ TEXT/ALFA]
############################################################################# ############################################################################# # # latex.tcl, version 4.1: macros, menu, and key bindings for LaTeX users # ############################################################################# # # version 1.1 and 1.2 (11/10/92) by Richard T. Austin <austin@eecs.umich.edu> # versions 2.0--3.2 and 3.2t (3/97) by Tom Scavo <trscavo@syr.edu> # versions 4.0 onwards (9/97) by Vince Darley <darley@fas.harvard.edu> # If you make improvements to this file, please share them! # # LaTeX 2.09 is no longer supported. If someone wants to make the # necessary changes to support it, they are welcome. ############################################################################# ############################################################################# # Initialize TeX mode: alpha::mode TeX 4.1.1 texMenu \ {*.tex *.ltx *.dtx *.ins *.cls *.clo *.sty *.log *.aux \ *.bbl *.idx *.ind *.glo *.gls *.toc *.lof *.lot *.blg *.ilg } texMenu { addMenu texMenu "•270" set unixMode(latex) {TeX} alpha::package require Alpha 7.0 # Reset the search path so it will be rebuilt the next time it's needed: set TeXSearchPath {} # Initialize TeX-related application signatures: foreach app {tex viewDVI printDVI dvips viewPS printPS bibtex makeindex} { ensureset ${app}Sig {} } # Install the short LaTeX menu, by default: ensureset useShortLaTeXMenu 1 # Do not load AMS-LaTeX, by default: ensureset useAMSLaTeX 0 # To add a new fileset type, all we have to do is this: set fileSetsTypesThing(tex) "tex" lappend fileSetsTypes "tex" } maintainer { "Vince Darley" darley@fas.harvard.edu <http://www.fas.harvard.edu/~darley/> } uninstall {this-directory} help {file "LaTeX Help"} ############################################################################# # # Autoload procedures # ############################################################################# proc dummyTeX {} {} proc texMenu {} {} ############################################################################# # # Flags and variables # ############################################################################# # Flags --- # if a particular template requires a certain package, warn if it's not there. newPref f warnIfPackageNotIncluded 1 TeX newPref f buildPkgsSubmenu 0 TeX newPref f deleteEnvNoisily 1 TeX newPref f deleteObjNoisily 1 TeX newPref f promptNoisily 1 TeX newPref f runTeXInBack 0 TeX makeTypesetMenu newPref f searchNoisily 1 TeX newPref f smartDots 1 TeX newPref f smartQuotes 1 TeX # newPref f useBoxMacro 1 TeX newPref f useBrackets 0 TeX newPref f useDollarSigns 0 TeX shadowUseDollarSigns newPref f useStatusBar 1 TeX newPref f wordWrap 1 TeX newPref f electricTab 1 TeX newPref v boxMacroNames {includegraphics includegraphics*} TeX shadowBoxMacroNames newPref v citeCommands {cite nocite citet citep citeyear} TeX shadowCiteRefCommands newPref v fillColumn {70} TeX newPref v funcExpr {\\(sub)*section(\[.*\]|\*)?({[^{}]*})?} TeX newPref v parseExpr {[^\{]*\{(.*)\}[^\}]*} TeX newPref v funcExprAlt {\\section(\[.*\]|\*)?({[^{}]*})?} TeX newPref v leftFillColumn {0} TeX newPref v prefixString {% } TeX newPref v refCommands {ref eqref pageref} TeX shadowCiteRefCommands newPref v wrapBreak {(\w+|\\(\\\*?|[^A-Za-z\t\r*\s\]|[A-Za-z]+\*?))} TeX newPref v wrapBreakPreface {([^\w\]|.\\)} TeX newPref v wordBreak {([\w:-]+|\\(\\\*?|[^A-Za-z\t\r*\s\]|[A-Za-z]+\*?))} TeX newPref v wordBreakPreface {([^-\w:\]|.\\)} TeX set texParaCommands {\[|\]|begin|end|(protect\\)?label|(sub)*section\*?|subfigure|paragraph|centerline|centering|caption|chapter|item|bibitem|intertext|(protect\\)?newline|includegraphics\*?} newPref v TeXInputsFolder "" TeX shadowTeXInputs newPref binding smartSubscripts "/_<U" TeX "" 1 newPref binding smartSuperscripts "/^<U" TeX "" 1 ############################################################################# # # Initialization # ############################################################################# hook::register activateHook makeTypesetMenu TeX proc makeTypesetMenu {name} { menu::buildSome Typeset } # registered only if we're using Textures proc TexturescloseHook {name} { global Texturesconnections if {[info exists Texturesconnections]} { set winNames [map car $Texturesconnections] if { [set pos [lsearch -exact $winNames $name]] > -1 } { # Close Textures' connection: global texAppSign set TeXjob [cadr [lindex $Texturesconnections $pos]] AEBuild -r '$texAppSign(Textures)' BSRs Disc Jobi $TeXjob # Update list of connections: set Texturesconnections [lreplace $Texturesconnections $pos $pos] } } } proc TexturesLaunched {args} { global Texturesconnections set Texturesconnections "" } # The proc 'shadowtexSig' is executed automatically whenever # the global variable 'texSig' is altered, say, by choosing # 'removedSavedSetting' on the Config menu. Alpha now has # a nifty proc to handle all the hard work for us: (Vince) proc shadowtexSig {args} { global packagesSubmenuItems TeXSearchPath texSig texAppSign # Reset the Packages submenu so that it will be rebuilt: set packagesSubmenuItems "" message {Building LaTeX menu…} buildLaTeXMenuQuietly # Reset the search path so it will be rebuilt the next time it's needed: set TeXSearchPath {} # Set things up for Textures if {[info exists texAppSign(Textures)] && \ $texSig == $texAppSign(Textures)} { hook::register launch TexturesLaunched $texAppSign(Textures) hook::register closeHook TexturescloseHook TeX } else { hook::deregister launch TexturesLaunched $texAppSign(Textures) hook::deregister closeHook TexturescloseHook TeX } } proc shadowTeXInputs {args} { global packagesSubmenuItems TeXSearchPath # Reset the Packages submenu so that it will be rebuilt: set packagesSubmenuItems "" message "Rebuilding the Documents submenu…" eval [TeX::sub::Documents] message "" # Reset the search path so it will be rebuilt the next time it's needed: set TeXSearchPath {} } # The proc 'shadowUseDollarSigns' is executed automatically whenever # the flag 'useDollarSigns' is altered. The proc 'mathModeSubmenu' # is defined in latexMenu.tcl. proc shadowUseDollarSigns {args} { TeX::sub::MathModes menu::buildSome "Math Modes" } # we indent to previous non-comment line, +- a bit for \begin or \end proc TeX::indentLine {} { set beg [lineStart [getPos]] set text [getText $beg [nextLineStart $beg]] regexp {^[ \t]*} $text white set next [expr $beg +[string length $white]] set lwhite [TeX::correctIndentation [getPos] \ [getText $next [pos::math $next + 5]]] set lwhite [text::indentOf $lwhite] if {$white != $lwhite} { replaceText $beg $next $lwhite } goto [expr $beg + [string length $lwhite]] } proc TeX::correctIndentation {pos {next ""}} { global indentationAmount set beg [lineStart $pos] # find last non-empty, non-comment line if [catch {search -s -f 0 -r 1 -i 0 -m 0 {^[ \t]*[^ \t\r%]} [expr $beg-1]} lst] { return 0 } set line [getText [lindex $lst 0] [expr [nextLineStart [lindex $lst 0]] - 1]] set lwhite [posX [expr [lindex $lst 1] - 1]] if {[regexp {^[ \t]*\\begin\{} $line]} { incr lwhite $indentationAmount } if [regexp {^\\end\{} $next] { incr lwhite -$indentationAmount } # only happens with poorly formatted files. if {$lwhite < 0} {return 0} else {return $lwhite} } ############################################################################# # # Colorization # ############################################################################# newPref v keywordColor blue TeX newPref v sectionColor magenta TeX newPref v commentColor red TeX newPref v bracesColor green TeX # The proc 'shadowCiteRefCommands' is executed whenever the variables # TeXmodeVars(citeCommands) or TeXmodeVars(refCommands) are changed. proc shadowCiteRefCommands {args} { global TeXmodeVars set LaTeXClickWords {} # insure that 'citeCommands' contains "cite" and "nocite": lunion TeXmodeVars(citeCommands) cite nocite foreach word $TeXmodeVars(citeCommands) { lappend LaTeXClickWords "\\\\$word" } # insure that 'refCommands' contains "ref" and "pageref": lunion TeXmodeVars(refCommands) ref pageref foreach word $TeXmodeVars(refCommands) { lappend LaTeXClickWords "\\\\$word" } # color and underline command-double-clickable LaTeX commands: regModeKeywords -a -u -k $TeXmodeVars(keywordColor) TeX $LaTeXClickWords } # The proc 'shadowBoxMacroNames' is executed whenever the variable # TeXmodeVars(boxMacroNames) is changed. proc shadowBoxMacroNames {args} { global TeXmodeVars set LaTeXClickWords {} foreach word $TeXmodeVars(boxMacroNames) { lappend LaTeXClickWords "\\\\$word" } # color and underline command-double-clickable LaTeX commands: regModeKeywords -a -u -k $TeXmodeVars(keywordColor) TeX $LaTeXClickWords } proc colorLaTeXClickCommands {} { global TeXmodeVars lappend LaTeXClickWords \\documentclass \\usepackage \ \\input \\include \ \\bibliography \\bibliographystyle \ \\LoadClass \\RequirePackage # color and underline command-double-clickable LaTeX commands: regModeKeywords -a -u -k $TeXmodeVars(keywordColor) TeX $LaTeXClickWords shadowCiteRefCommands shadowBoxMacroNames } proc colorLaTeXCommands {} { global TeXmodeVars set LaTeXKeyWords {} # Color comments, braces and dollar signs, and all LaTeX commands: regModeKeywords -i "\}" -i "\{" -i "\$" -I $TeXmodeVars(bracesColor) \ -e {%} -m {\\} -c $TeXmodeVars(commentColor) \ -k $TeXmodeVars(keywordColor) TeX $LaTeXKeyWords # Color sectioning commands: regModeKeywords -a -k $TeXmodeVars(sectionColor) TeX \ { \\part \\chapter \\section \\subsection \\subsubsection \\paragraph } } colorLaTeXCommands; rename colorLaTeXCommands "" colorLaTeXClickCommands; rename colorLaTeXClickCommands "" ############################################################################# # # LaTeX initialisation # ############################################################################# if [alpha::try "Initialising LaTeX" \ latexEngine.tcl {} \ latexComm.tcl {}\ latexMacros.tcl {}\ latexMenu.tcl {} \ latexKeys.tcl {} \ bindLaTeXKeys {Binding LaTeX keys} \ [list app::registerMultiple tex [list OTEX *TEX *XeT MPS*] \ [list •266 •267 •272 •299] shadowtexSig] {Building LaTeX menu}] { rename bindLaTeXKeys "" }